#include<bits/stdc++.h>
using namespace std;

struct qujian{
  int l,r;
};

bool cmp(qujian a,qujian b){
  return a.l<b.l;
}

int main(){
  int n;
  cin>>n;
  vector<qujian> q;
  vector<qujian> qq;
  while(n--){
    int l,r;
    cin>>l>>r;
    q.push_back({l,r});
  }
  sort(q.begin(),q.end(),cmp);
  qq.push_back(q[0]);
  for(int i=1;i<q.size();i++){
    auto& last = qq.back();
    if (q[i].l <= last.r) {
      last.r = max(last.r, q[i].r);
    }else{
      qq.push_back(q[i]);
    }
  }
  for(int i=0;i<qq.size();i++){
    cout<<qq[i].l<<" "<<qq[i].r<<endl;
  }

  return 0;
}